package store.lunangangster.engine.impl.entity.mgr;

import java.util.List;
import store.lunangangster.engine.ProcessEngineConfiguration;
import store.lunangangster.engine.impl.entity.ProcessDefinitionEntity;
import store.lunangangster.engine.impl.entity.ProcessDefinitionEntityImpl;
import store.lunangangster.engine.impl.query.ProcessDefinitionQuery;

public class ProcessDefinitionEntityManagerImpl extends AbstractEntityManagerImpl<ProcessDefinitionEntity> implements ProcessDefinitionEntityManager {

  public ProcessDefinitionEntityManagerImpl(
      ProcessEngineConfiguration processEngineConfiguration) {
    super(processEngineConfiguration);
  }

  @Override
  public Class<? extends ProcessDefinitionEntity> getManagedEntityClass() {
    return ProcessDefinitionEntityImpl.class;
  }

  @Override
  public ProcessDefinitionEntity create() {
    return new ProcessDefinitionEntityImpl();
  }

  @Override
  public int selectCount(ProcessDefinitionQuery query) {
    return (int) getDbSqlSession().selectOne("selectProcessDefinitionCountByCondition", query);
  }

  @Override
  @SuppressWarnings("unchecked")
  public List<ProcessDefinitionEntity> selectProcessDefinitionByCondition(ProcessDefinitionQuery query) {
    return (List<ProcessDefinitionEntity>) getDbSqlSession().selectList("selectProcessDefinitionByCondition", query);
  }

  @Override
  public List<ProcessDefinitionEntity> selectLatestProcessDefinitionByDeploymentId(String deploymentId) {
    return selectList("selectLatestProcessDefinitionByDeploymentId", deploymentId, null);
  }

  @Override
  public ProcessDefinitionEntity selectLatestProcessDefinitionByKey(String processDefinitionKey) {
    return selectOne("selectLatestProcessDefinitionByKey", processDefinitionKey, null);
  }

}
